/*
 * @Author: DUST
 * @Date: 2023-05-28 09:47:15
 * @LastEditors: DUST
 * @LastEditTime: 2023-05-28 09:49:36
 * @FilePath: \koa-node-ts\utils\responese.ts
 * @Description:
 * undefined
 */
import { Context } from "koa";

class responseData {
  /**
   * @description:
   * @param {Context} ctx
   * @param {any} data:返回数据
   * @param {string} msg：返回的结果信息提示
   * @param {number} code:返回结果状态码
   */
  success = (
    ctx: Context,
    data: any = null,
    msg: string = "操作成功",
    code: number = 0
  ) => {
    ctx.body = {
      code,
      data,
      msg,
    };
  };
  /**
   * @description:
   * @param {Context} ctx
   * @param {string} msg：返回错误信息
   * @param {number} code：返回错误状态码
   * @param {any} data
   */
  errorResponese = (
    ctx: Context,
    msg: string = "操作失败",
    code: number = -1,
    data: any = null
  ) => {
    ctx.body = {
      code,
      data,
      msg,
    };
  };
};

export default new responseData;
